<template>
	<el-dialog title="修改" :close-on-click-modal="false" :visible.sync="visible" width="65%" :modal="false" append-to-body>
		<el-form :model="dataForm" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="120px" :inline="true">
			<el-form-item v-for="(value ,_key) in subCfg.subCfgMap" :key="_key" :prop="_key" :label="value">
				<el-input v-model="dataForm[_key]" type="text"></el-input>
			</el-form-item>
		</el-form>
		<span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
	</el-dialog>
</template>

<script>
	import dateUtil from '@/utils/dateUtil'
	export default {
		data() {
			return {
				visible: false,
				dataForm: {
					ext1:'',
					ext2:'',
					ext3:'',
					ext4:'',
					ext5:'',
					ext6:'',
					ext7:'',
					ext8:'',
					ext9:'',
					ext10:'',
				},
				id: '',
				cusFieldList: [],
				cusInfoId:'',
				subCfg :'',
				
			}
		},
		filters: {
			formatDateTime(timestamp) {
				return dateUtil.formatDateTime(timestamp)
			}
		},
		created() {

		},
		methods: {
			init(row,item) {
				var that = this
				that.clean()
				that.visible = true
				that.cusInfoId = item.cusInfoId
				that.subCfg = item
				that.dataForm.id = row.id
				that.dataForm.ext1 = row.ext1
				that.dataForm.ext2 = row.ext2
				that.dataForm.ext3 = row.ext3
				that.dataForm.ext4 = row.ext4
				that.dataForm.ext5 = row.ext5
				that.dataForm.ext6 = row.ext6
				that.dataForm.ext7 = row.ext7
				that.dataForm.ext8 = row.ext8
				that.dataForm.ext9 = row.ext9
				that.dataForm.ext10= row.ext10

			},
			// 表单提交
			dataFormSubmit() {
				var that = this
				if(that.dataForm.ext1 == '' && that.dataForm.ext2 == '' && that.dataForm.ext3 == '' 
					&& that.dataForm.ext4 == '' && that.dataForm.ext5 == '' && that.dataForm.ext6 == ''
					&& that.dataForm.ext7 == '' && that.dataForm.ext8 == '' && that.dataForm.ext9 == ''
					&& that.dataForm.ext10 == '') {
					this.$message({
						message: '字段不能全为空！',
						type: 'warning',
						duration: 1500,
					})
					return false
				}
				that.$refs['dataForm'].validate((valid => {
					if(valid) {
						this.$prompt('请输入修改备注', '提示', {
							confirmButtonText: '确定',
							cancelButtonText: '取消',
							inputPattern:  /\S/,
							inputErrorMessage: '请填写修改备注'
						}).then(({ value }) => {
							this.$http.post('/cc/customer/sub/info/update', {
								id: that.dataForm.id,
								ext1: that.dataForm.ext1,
								ext2: that.dataForm.ext2,
								ext3: that.dataForm.ext3,
								ext4: that.dataForm.ext4,
								ext5: that.dataForm.ext5,
								ext6: that.dataForm.ext6,
								ext7:that.dataForm.ext7,
								ext8: that.dataForm.ext8,
								ext9: that.dataForm.ext9,
								ext10: that.dataForm.ext10,
								updateDesc:value,
								cusInfoId:that.subCfg.cusInfoId
							}).then(res => {
								if(res.data.code === '0'){
									that.$message({
										message: '修改成功',
										type: 'success',
										duration: 1000,
										onClose: () => {
											that.$emit('refreshDataList')
										}
									});
									that.visible = false
								}else{
									that.$message.error('操作失败')
								}
							})
						}).catch(() => {});
					}	
				}))
			},
			
			clean(){
				var that = this
				that.dataForm.ext1=''
				that.dataForm.ext2=''
				that.dataForm.ext3=''
				that.dataForm.ext4=''
				that.dataForm.ext5=''
				that.dataForm.ext6=''
				that.dataForm.ext7=''
				that.dataForm.ext8=''
				that.dataForm.ext9=''
				that.dataForm.ext10=''
			}

		}
	}
</script>